package ca.kooki.codesnippet;

import junit.framework.Assert;

import org.junit.Test;

import ca.kooki.codesnippet.core.User;

public class ActivatorTest {

  
  @Test
  public void DefaultRepository()
  {
    Activator activator = new Activator();
    CodeSnippetRepository repository = activator.getRepository();
    
    Assert.assertEquals(InMemoryCodeSnippetRepository.class,repository.getClass());
    
  }

  @Test
  public void GetRepositoryNoUser()
  {
    Activator activator = new Activator();
    CodeSnippetRepository repo = activator.getRepository();
    Assert.assertEquals(User.ANNONYMOUS, repo.getUser());
  }

  @Test
  public void GetRepositoryHasUser()
  {
    Activator activator = new Activator();
    CodeSnippetRepository repo = activator.getRepository();
    User user = new User("aforward");
    repo.addUser(user);
    activator.getPreferences().setValue("user", "aforward");
    repo = activator.getRepository();
    Assert.assertEquals(user,repo.getUser());
  }

  @Test
  public void GetRepositoryCreateUserIsNotAlready()
  {
    Activator activator = new Activator();
    activator.getPreferences().setValue("user", "aforward");
    CodeSnippetRepository repo = activator.getRepository();
    
    Assert.assertEquals("aforward",repo.getUser().getName());
    Assert.assertEquals(true,repo.getUser().isOfficial());
  }
  
  @Test
  public void FileSystemRepository()
  {
    Activator activator = new Activator();
    activator.getPreferences().setValue("repository_file", "abc.xml");
    CodeSnippetRepository repository = activator.getRepository();
    
    Assert.assertEquals(FileSystemCodeSnippetRepository.class,repository.getClass());
  }

  
  @Test
  public void InMemoryRepository()
  {
    Activator activator = new Activator();
    activator.getPreferences().setValue("repository_file", "InMemory");
    CodeSnippetRepository repository = activator.getRepository();
    
    Assert.assertEquals(InMemoryCodeSnippetRepository.class,repository.getClass());
  }
  
  
}
